package com.example.temp;

import java.util.ArrayList;

public class Test18 {

    public static void main(String[] args) {

//        int[][] a = {{22,15,32,20,18},{12,21,25,19,33},{14,58,34,24,66}};
//
//        System.out.println(a.length);
//        System.out.println(a[0].length);\
        System.out.println((Math.min(4,5)-1)/2+1);
    }

    /**
     * 输入一个矩阵，按照从外向里以顺时针的顺序依次打印出每一个数字，
     * 例如，如果输入如下4 X 4矩阵：
     * 1    2    3   4
     * 5    6    7    8
     * 9    10   11   12
     * 13    14  15    16
     * 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10.
     */

    public class Solution {
        public ArrayList<Integer> printMatrix(int [][] matrix) {
            ArrayList answer = new ArrayList();
            if (matrix.length==0||matrix[0].length==0) return answer;
            int n = matrix.length;
            int m = matrix[0].length;
            int layers = ((n<m?n:m)+1)/2;
            for (int i = 0; i < layers; i++) {
                for (int j = i; j < m-i; j++) {
                    answer.add(matrix[i][j]);
                }
                for (int j = i+1; j < n-i; j++) {
                    answer.add(matrix[j][m-i-1]);
                }
                //<--- 除了j>=i  还需要
                for (int j = m-i-2; j >=i&&n-i-1!=i; j--) {
                    answer.add(matrix[n-i-1][j]);
                }
                //向上
                for (int j = n-i-2; j > i&&m-i-1!=i; j--) {
                    answer.add(matrix[j][i]);
                }

                
            }
            return answer;

        }

    }
}
